home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_098 / thai / article < prev    next >
Text File  |  1992-05-06  |  12KB  |  213 lines

  1. [
  2. Alan Kent
  3. 22 Wallabah St
  4. Mt Waverley 3149
  5.  
  6. Alan Kent     (RMIT, Melbourne, AUSTRALIA)
  7. UUCP: {seismo,hplabs,mcvax,ukc,nttlab}!munnari!goanna.oz!ajk
  8. ARPA: munnari!goanna.oz!ajk@SEISMO.ARPA
  9. ACSnet: ajk@goanna.oz
  10. ]
  11.  
  12.               TALKING THAI
  13.  
  14. Ever wanted to do a project to show off the real power of the Amiga
  15. compared to all those other inferior machines?  This was not the reason
  16. I started this project, but looking back, it was certainly easier than
  17. it would have been on most machines.  Recently I have been trying to
  18. learn Thai (Why you ask? Well, I knew Pascal, Cobol, Fortran, C, Basic
  19. etc., so why not learn another language!). I have not given up yet, but
  20. I have realised that human languages are a LOT more complex than
  21. computer languages.  To aid myself in learning the language, I thought
  22. it would be useful to write a program to quiz me on the English/Thai
  23. translation of words. For fun I then tried to get the Amiga to speak
  24. the words in Thai so I could listen to what the words should sound
  25. like.  Unfortunately Thai has over 20 vowel sounds, many of which the
  26. Amiga's narrator does not support, so the end result was far from
  27. accurate.  The narrator device is the software that allows the Amiga to
  28. speak.  In this article I thought I would describe some of the
  29. experiences I had in trying to get this program going.
  30.  
  31.         WRITING SOFTWARE WITH INTUITION
  32.  
  33. Most of the software I have written in the past has been C under UNIX
  34. and was to be used on normal computer terminals. As a result, the
  35. interface was pretty limited.  The Amiga, as you know, has a much more
  36. powerful interface which can be accessed through a library called
  37. Intuition. This allows the easy use of features such as menus and
  38. gadgets which are controlled by combinations of mouse and keyboard
  39. input.  It is very useful that most of the interface code (such as for
  40. controlling menus) is already written for you.
  41.  
  42. Briefly, a gadget is Intuition's main form of user input.  There are
  43. actually three main types of gadgets. Boolean gadgets are simply boxes
  44. or images on the screen that you click on (for example, the depth
  45. arranging gadgets in the top right hand corner of windows),
  46. proportional gadgets are basically slide bars and string gadgets allow
  47. text to be entered in a rectangular area on the screen. String gadgets
  48. can be used to accept numbers rather than straight text.  A requester
  49. is a rectangular area that appears, for example, when a program asks
  50. for a filename. Requesters use gadgets to actually accept input from
  51. the user.
  52.  
  53. Personally, I dislike using menus for commands I use frequently.
  54. Moving the mouse up to the top of the screen, then dragging it down for
  55. the correct entry (the entries usually being packed quite closely
  56. together) can get annoying after a while, especially if you get the
  57. wrong entry and accidently erase the past 20 minutes work!  I prefer
  58. having great big boxes - big so they are very hard to miss - to click
  59. on with the mouse.  As a result, my program ended up using lots and
  60. lots of boolean gadgets all over the screen and no menu bar at the top.
  61. One disadvantage I found in doing this is that if you have too many
  62. gadgets, it can take quite a while to refresh them all. My program
  63. takes about a second, which is just long enough to be annoying.
  64.  
  65. One problem that stumped me for a little while was how to output error
  66. messages.  My screen for this particular program had ended up so densly
  67. packed that there was no room left for printing error messages
  68. anywhere. I finally realised that I could use a requester for both
  69. error messages and to accept answers to simple yes/no type questions.
  70. (It often takes me a while to see the obvious).  The intuition function
  71. AutoRequester() automatically builds a requester to accept a yes/no
  72. type answer - all the user needs to supply is the size of the requester
  73. and text to go in it.  These requesters are exactly like the `Please
  74. insert disk X into any drive' with `Cancel' and `Retry' selections that
  75. AmigaDOS often generates.  To output an error message, I simply used a
  76. requester with only a `Cancel' selection.  The end result, while simple
  77. to achieve, looks great compared to previous terminal based programs I
  78. had written.
  79.  
  80.             A THAI QUIZ PROGRAM
  81.  
  82. The above is valid for any program that uses intuition.  My Thai quizer
  83. program however added a few more problems.  The program basically
  84. allows both sentences and words to be entered in both English and Thai,
  85. plus the phonetic spelling of the Thai words.  For example the phonetic
  86. spelling of CAT may be written as KAAT (K, AA, T).  There are several
  87. different standards for phonetic spelling, the main difference being
  88. which english letter or letters are used to represent the sound.  The
  89. phonetic alphabet I ended up using is not the same as what the Amiga's
  90. narrator device uses, mainly because the narrator does not have all the
  91. sounds that exist in Thai.  Note that the Amiga's narrator device
  92. accepts all input in phonetics. To make the Amiga speak English
  93. involves using a translator library to convert the English text into
  94. phonetics.
  95.  
  96. Once words or sentences have been entered, the program can then be used
  97. to either search for a word by Thai, English or phonetic spelling, or
  98. randomly choose words to quiz you on. It does not help with learning
  99. the structure of Thai sentences much, but it certainly does help
  100. learning individual words and common sentences.
  101.  
  102. Rather than translate the Thai into phonetics myself, I wrote some code
  103. to do it for me. Thai itself, luckily, is basically a phonetic language
  104. - that is the pronunciation of individual characters basically stays
  105. the same (not always of course! that would be TOO easy!).  English was
  106. apparently once a phonetic language, but this is no longer true
  107. (consider the words low and now - `ow' has different pronunciations in
  108. the two words).  The translation of single words at present only works
  109. perfectly about 50% of the time. 40% of the time minor corrections need
  110. to be made.  The other 10% of the time, the translation fails
  111. completely.  If nothing else, the automatic translation reduces the
  112. amount of typing required to enter the phonetic version of the Thai
  113. words.
  114.  
  115. Translating complete sentences is easier as the dictionary of
  116. pre-translated words can be used to do a word by word translation.  The
  117. translation of complete sentences still has one minor problem in that
  118. Thai does not have spaces between words! It just allrunstogether!
  119.  
  120. Another problem I came across was that the Thai language has its own
  121. character set. The Amiga luckily provides the ability to handle
  122. different character sets or `fonts' so I was able to design my own
  123. using a font editor (there is one on a public domain disk somewhere and
  124. there will also be one supplied with V1.2 I believe). The font ended up
  125. being 22 pixels high (normal text is usually only 8 pixels high). This
  126. was because in Thai there are lots of symbols that can appear above,
  127. below, to the left or right of characters to change their meaning or
  128. pronunciation and all these symbols had to be included in the character
  129. set. Thai characters also have lots of little loops which makes them
  130. difficult to draw on a graphics screen so the actual characters cannot
  131. be reduced beyond a certain limit.  In total there are about 44
  132. consonants and 33 vowels in Thai, although many of the vowels are
  133. produced by using different combinations of a small number of symbols.
  134.  
  135. As Thai characters bear no relation to English characters, it is
  136. difficult to map all 77 or so Thai characters to keyboard keys in any
  137. way that could be easily remembered. As a result, I used boolean
  138. gadgets again at the top of the screen which showed what the characters
  139. look like. Entering text involves clicking gadgets with the mouse
  140. rather than using the keyboard.  Entering Thai text can be quite slow
  141. unfortunately, as you have to move the mouse around a lot, but it is
  142. easier than remembering the keyboard layout!  Using this approach means
  143. however that a string gadget cannot be used for Thai input fields.
  144.  
  145. Outputing Thai characters on a printer also presented a minor problem.
  146. The printer driver provides many useful features for outputing normal
  147. English text, but has relatively poor support for handling different
  148. fonts other than pure ASCII. The solution appears to be to allocate an
  149. area of graphics memory and to draw the characters into it. The final
  150. image can then be output with a `dump RastPort' command to the printer
  151. driver. The easiest way to achieve all this is to create an Intuition
  152. screen only as high as the character set (in my case 22 pixels) with a
  153. single bit plane (only colors black and white are needed) and then to
  154. use Intuition functions such as PrintIText() to output the Thai text
  155. into this screen. Dumping a screen's RastPort simply involves copying
  156. some information from the screen's Screen structure into the printer
  157. request block and sending the request to the printer driver.
  158.  
  159.             USING THE NARRATOR
  160.  
  161. Just for fun, I decided to try and get the program to speak the
  162. phonetic version of the Thai words. I did not really expect to get very
  163. good results (considering the quality of the Amiga's English
  164. pronunciation) but it was fun trying. There were two main problems I
  165. encountered and only partially overcame.
  166.  
  167. Unfortunately, Thai has got a lot more vowel sounds than English. The
  168. narrator device simply did not know about all the sounds I needed. The
  169. best I could do was either to pick the closest sounding one or string a
  170. few together. As I am not really sure myself what they are meant to
  171. sound like, I cannot be certain of the results.
  172.  
  173. Thai is a tonal language which means that the pitch of the sounds also
  174. affects their meaning. In Thai there are 5 basic `tones': common, low,
  175. high, rising and falling. In English, when asking a yes/no question for
  176. example, we normally raise the voice at the end of the question (`Are
  177. you well?').  This must not be done in Thai.  Just to make things that
  178. little bit more interesting (or confusing), the duration of sounds is
  179. also important (short or long). Each syllable in a Thai word then has
  180. its own sound (usually consisting of an initial consonant, a middle
  181. vowel and an optional final consonant), a tone, and a duration.  Trying
  182. to get the narrator to speak a multi-syllable word can get quite
  183. tricky!
  184.  
  185. To be able to get total control per syllable, it was necessary to send
  186. the narrator device one syllable at a time. This unfortunately resulted
  187. in significant pauses between each syllable as the narrator thought it
  188. was the end of a sentence. I have found no way to get around this
  189. problem. Sending a separate command per syllable makes the duration
  190. easy to control.  The common, high and low tones are also simple - just
  191. use the robotic (monotone) voice and change the pitch.  The rising and
  192. falling tones are harder, but are possible by using the natural
  193. (contoured) voice.  Adding a '.' at the end of the syllable (to make it
  194. think that its the end of a sentence) generates a falling tone and
  195. adding a '?' generates a rising tone.
  196.  
  197.             CONCLUSIONS
  198.  
  199. The Amiga with Intuition sure makes it easier to do nice interfaces.
  200. It provides lots of easy, ready to use functions to handle gadgets and
  201. menus. What I really would like though is an easier way of designing
  202. the menus, gadgets, windows etc. without having to recompile the
  203. program. I have heard (in other words I really don't know) that the Mac
  204. allows such definition files that can be modified to change the
  205. interface to the program without the program requiring recompilation.
  206. Looking at the latest public domain disks however there seems to be a
  207. gadget editor (egad) which I will have to have examine, and there was a
  208. menu editor on an earlier disk too.
  209.  
  210. The next things I want to have a go at are the animation routines and a
  211. bit of music. Then I can get onto some serious stuff, like writing a
  212. few games!
  213.